Copy attributes from one object to another.

Is there a way to copy all the attribute content from one object to another object. I can copy the object, but when pasted an new object is created and I only want to modify the exisiting object.
lahines - Wed Apr 13 10:04:31 EDT 2011

Re: Copy attributes from one object to another.
jdoucement - Wed Apr 13 10:54:21 EDT 2011

Hi,

I know a way, but it's not as easy as it looks.
Are the objects within the same module? If not, you must first ensure that concerned attributes exist on both sides, or at least you must point out the attribute(s) value(s) you want to copy.
Then, you should use a "for attribute in module" loop (refer to the DXL user manual), eventually inside a "for object in module" loop.
As always, it depends on what you're trying to achieve. Give more details if you need a more precise answer.

Cheers.

Re: Copy attributes from one object to another.
lahines - Wed Apr 13 11:17:12 EDT 2011

jdoucement - Wed Apr 13 10:54:21 EDT 2011
Hi,

I know a way, but it's not as easy as it looks.
Are the objects within the same module? If not, you must first ensure that concerned attributes exist on both sides, or at least you must point out the attribute(s) value(s) you want to copy.
Then, you should use a "for attribute in module" loop (refer to the DXL user manual), eventually inside a "for object in module" loop.
As always, it depends on what you're trying to achieve. Give more details if you need a more precise answer.

Cheers.

I have about information in about 20 user created attributes. The data is currently in another module but the entire object can be copied between modules so that the information will be in the same module. Identical attributes are in both modules. I need the object ID remain the same.

Re: Copy attributes from one object to another.
llandale - Wed Apr 13 15:33:42 EDT 2011

Let me scribble, debug it yourself:

void  CopyAllAttrValues(Object oFrom, oTo, bool IgnoreHeadingText)
{    // Copy all attribute values from the "oFrom" object to the "oTo" object.
     // Optionally don't copy Object Heading nor Object Text
     // Ignore write errors
     // Do NOT erase oTo values that oFrom doesn't have, such as when they
     //    are in different modules with different attributes.
 
     if (null oFrom or null oTo) return
 
     AttrDef ad 
     string NameAttr
     for ad in module(oFrom) do
     {  if (!ad.object)  continue     // This attr isn't for objects  (e.g. "Prefix")
        if (!ad.useraccess) continue  // you may not modify this attr (e.g. "Last Modified On")
        NameAttr = ad.name
        if (IgnoreHeadingText      and
            (NameAttr == "Object Heading" or NameAttr == "Object Text")) continue
        noError()
        set(oTo.NameAttr, oFrom.NameAttr)
        lastError()
     }
}


I'm pretty sure the noError/lastError will cover the case that there is no NameAttr in the module containing oTo.

If it were me doing this for lots of objects, I'd first find all the object-attr-names in the oFrom module, store them in a Skip, then send the Skip to the Function. That will drastically speed things up since the "for ad in module" loop is actually pathetically low, which matters when copying 1000s of objects.

 

 

  • Louie

 

 

Re: Copy attributes from one object to another.
lahines - Wed Apr 13 15:59:04 EDT 2011

llandale - Wed Apr 13 15:33:42 EDT 2011

Let me scribble, debug it yourself:

void  CopyAllAttrValues(Object oFrom, oTo, bool IgnoreHeadingText)
{    // Copy all attribute values from the "oFrom" object to the "oTo" object.
     // Optionally don't copy Object Heading nor Object Text
     // Ignore write errors
     // Do NOT erase oTo values that oFrom doesn't have, such as when they
     //    are in different modules with different attributes.
 
     if (null oFrom or null oTo) return
 
     AttrDef ad 
     string NameAttr
     for ad in module(oFrom) do
     {  if (!ad.object)  continue     // This attr isn't for objects  (e.g. "Prefix")
        if (!ad.useraccess) continue  // you may not modify this attr (e.g. "Last Modified On")
        NameAttr = ad.name
        if (IgnoreHeadingText      and
            (NameAttr == "Object Heading" or NameAttr == "Object Text")) continue
        noError()
        set(oTo.NameAttr, oFrom.NameAttr)
        lastError()
     }
}


I'm pretty sure the noError/lastError will cover the case that there is no NameAttr in the module containing oTo.

If it were me doing this for lots of objects, I'd first find all the object-attr-names in the oFrom module, store them in a Skip, then send the Skip to the Function. That will drastically speed things up since the "for ad in module" loop is actually pathetically low, which matters when copying 1000s of objects.

 

 

  • Louie

 

 

Thanks for the script and suggestions. I will give this a try tomorrow. It looks like it will save tons of time.

Re: Copy attributes from one object to another.
Lion29 - Wed Apr 13 20:12:18 EDT 2011

There is a cheap trick for updating all the object attributes in the same module

1. In case, if all the objects in the module should be updated with the same attribute text, then select any object and fill in the text. After filling in the data for the attribute, there will be an radio buttons to fill the same text for the attribute in current module.

2. In case, if a selected objects in the module should be updated with the same attribute text, then apply filter over the module. After performing the filter, fill in the attribute with the new text and select the radio button. Select the radio button to fill in the same data in the current view.

Re: Copy attributes from one object to another.
lahines - Thu Apr 14 06:59:30 EDT 2011

Lion29 - Wed Apr 13 20:12:18 EDT 2011
There is a cheap trick for updating all the object attributes in the same module

1. In case, if all the objects in the module should be updated with the same attribute text, then select any object and fill in the text. After filling in the data for the attribute, there will be an radio buttons to fill the same text for the attribute in current module.

2. In case, if a selected objects in the module should be updated with the same attribute text, then apply filter over the module. After performing the filter, fill in the attribute with the new text and select the radio button. Select the radio button to fill in the same data in the current view.

In this instance, I have 150 objects and 20 attributes in each objec, which have to be copied from 150 other objects, without changing the object number.

Re: Copy attributes from one object to another.
Lion29 - Thu Apr 14 11:41:20 EDT 2011

lahines - Thu Apr 14 06:59:30 EDT 2011
In this instance, I have 150 objects and 20 attributes in each objec, which have to be copied from 150 other objects, without changing the object number.

For this specific case, perform a filter in such a way that only the 150 objects shows up in the module, select any single object and perform the below mentioned steps
1. right click over the object and goto properties.
2. Fill the Attribute Value in the text box.
3. In the "Apply to", select "Objects in current view"
4. Then Click OK.

Perform the same for each of the attribute.
Attachments

attachment_14606706_untitled.JPG